
<template>
  <div class="user-index">  
    <div  v-if="homePageSwitch==1||homePageSwitch==3"  class="head-back" @click="goBack"  :style="'height:'+headHeight+'rpx;padding-top:'+headPadding+'rpx;'">  
      <div class="tabs-item " @click="jumpTabs(0)"> 
        <image :src="currentTab==0?'/static/image/user-avtive.png':'/static/image/user.png'" class="user-img"/>
      </div>
      <div class="tabs-item tabs tabs-padding">
        <div class="switch-box">
          <div class="icon-box">
            <div class="icon-img-box" @click="jumpTabs(1,1)" >
              <image :src="currentTab==1&&!bestPageShow?'/static/image/home-active.png':'/static/image/home.png'" class="img left"  />
            </div>
            <div class="icon-img-box" @click="jumpTabs(1,2)" >
              <image :src="currentTab==1&&bestPageShow?'/static/image/jewel-active.png':'/static/image/jewel.png'" class="img right best-title-icon"/>
            </div>  
          </div> 
          <div class="round" :class="{'round-active':bestPageShow}"></div>
        </div>  
      </div> 
      <div class="tabs-item tabs"   @click="jumpTabs(2)"> 
        <image :src="currentTab==2?'/static/image/message-active.png':'/static/image/message.png'" class="img msg-img"/>
        <span class="hongdian" v-if="unreadMsgNum>0"></span>
      </div>
    </div>   
     <!--页面内容 -->
    <swiper class="tab-box" :current="currentTab" duration="300" @change="switchTab" style="height:100%;"> 
        <!--个人主页-->
        <swiper-item  class="tab-content">
          <div class="user-page" :style="'padding-top:'+headHeight+'rpx'">
            <div class="user-page-content">
              <div class="header text-center">
                <image mode="aspectFill" :src="userInfo.head_pic?userInfo.head_pic:'https://ximi-jy.oss-cn-hangzhou.aliyuncs.com/quyue/image/head-img-undefined.png'" class="head-img"  @click="jumpPage('./../../home-page/my-home-page/main')"></image>
                <div class="name text-center">{{userInfo.nickname?userInfo.nickname:'未设置'}}{{userInfo.age?','+userInfo.age:''}}</div> 
                <div class="site text-center">{{userInfo.city}}</div> 
              </div>
              <div class="edit-group"> 
                <div class="edit-item text-center" @click="jumpPage('./../../user-info/set-page/main')">
                  <image mode="aspectFill" src='/static/image/user-page-set.png' class="edit-img"></image> 
                  <div class="text-center">设置</div>
                </div>
                <div class="edit-item hobbies-item text-center " @click="jumpPage('./../../user-info/user-books/main?tabsId=1')">
                  <image mode="aspectFill" src='/static/image/user-page-hobbies.png' class="edit-img"></image> 
                  <div class="text-center">影·音·书</div>
                </div>
                <div class="edit-item text-center" @click="jumpPage('./../../user-info/edit-user-info/main')">
                  <image mode="aspectFill" src='/static/image/user-page-edit.png' class="edit-img"></image> 
                  <div class="text-center">编辑信息</div>
                </div> 
              </div>  
            </div>
            <div class="user-footer">
              <div class="footer-box text-center"> 
                  <swiper
                    :indicator-dots="false"
                    :circular="true"
                    :autoplay="userPageAutoPlay"
                    :interval="2500"
                    :duration="500"
                    :current="userHmowCurrent" 
                    @change="userSwiperChange"
                    style="height:100%;width:100%;"
                  >
                    <block v-for="item in userIndexBanner" :key="item" >
                      <swiper-item style="display:flex;align-items:center;justify-content:center;">
                        <image :src="item" style="height:90rpx;" mode="aspectFit"/>
                      </swiper-item> 
                    </block>
                  </swiper> 
                <div class="absolute-footer"> 
                  <div class="dots text-center"> 
                    <span class="indicator" v-for="(item,index) in userIndexBanner"  :key="item" :class="{'indicator-active':userHmowCurrent==index}"></span> 
                  </div> 
                  <div class="btn" @click="jumpPage('./../../user-info/vip-set-page/main')">我的超级特权</div>
                  <!--<div class="btn" @click="jumpPage('./../../home-page/ceshi/main')">我的超级特权</div>-->
                </div> 
              </div>
            </div>
          </div>
        </swiper-item>
      <!--列表页-->
      <swiper-item v-if="(userDataList.length>0&&!bestPageShow)&&homePageSwitch==1" class="tab-content c-movble home-page" >  
        <c-movble  
          :rollerAttr="userDataList[0].ruuid"  
          :userInfo="userInfoList" 
          :userDataList="userDataList"     
          :isSelect="isSelect" 
          :isHint="isHintShow"
          :superlikeNum="superlikeNum"
          :likeNumNull="likeNumNull"
          @openDetail="openDetail" 
          @isHintFun="isHintFun"
          @changeSelect="changeSelect">
        </c-movble>
      </swiper-item>
      <!--详情页-->
      <swiper-item v-if="(userDataList.length>0&&!bestPageShow)&&homePageSwitch==2" class="tab-content c-movble home-page" >   
        <scroll-view scroll-y  class="my-home-page" :style="'overflow-y:auto;height:100%;padding-top:'+statusBarHeight+'px'">   
          <div class="swiper"  :style="'top:'+statusBarHeight+'px'">
            <div class="indicator-box"  :style="'top:'+statusBarHeight+'px'">
              <div class="indicator-group" v-if="userImgList.length>1">
                <span v-for="(item,index) in userImgList" :key="item" :class="{'active':userDetailCurrent==index}"></span> 
              </div> 
            </div> 
            <swiper
              :indicator-dots="false"
              :autoplay="false"
              :interval="5000"
              :duration="100"
              :current="userDetailCurrent" 
              @change="bindchange"
              :style="'height:100%;width:100%;'"
            >
              <block v-for="item in userImgList" :key="item">
                <swiper-item class="swiper-img-box" >
                  <div style="width:100%;height:100%;" >
                    <image mode="aspectFill" :src="item.link" class="img"  :class="{'off-left':userDetailOffLeft,'off-right':userDetailOffRight}"/> 
                  </div>  
                </swiper-item>   
              </block>  
            </swiper> 
          </div>
          <!--内容--> 
          <div class="content-box" style="padding-top:0;"> 
            <div class="page-content"> 
              <div class="swiper-change">
                <div class="block-left" @click.stop="swiperClis('down')"></div> 
                <div class="block-right" @click.stop="swiperClis('up')"></div>
              </div> 
              <div class="basics-data page-basics-content">
                <div class="page-back " @click="homePageSwitch=1">
                  <image  src="/static/image/hmoe-back.png" :class="{'page-back-transform':homePageSwitch==2}" class="img"/> 
                </div>
                <div class="name">{{userInfoList.nickname}}&nbsp;&nbsp;<span>{{userInfoList.age}}</span></div>
                <div class="info-list " v-if="userInfoList.industry">
                  <image class="classroom-img " src="/static/image/home-classroom.png"></image>
                  <span>{{userInfoList.industry}}</span>  
                </div>
                <div class="info-list"  v-if="userInfoList.school">
                  <image class="school-img " src="/static/image/home-school.png"></image>
                  <span>{{userInfoList.school}}</span>  
                </div>
                <div class="info-list " >
                  <image class="location-img " src="/static/image/home-location.png"></image>
                  <span v-if="userInfoList.distance>=1"> {{userInfoList.distance}} km</span>  
                  <span v-else>一公里以内</span>  
                </div>
              </div>

              <div class="introduce" v-if="userInfoList.introduce"> {{userInfoList.introduce}} </div>

              <div class="audio-book"> 
                <div class="title"  v-if="userInfoList.length>=0">{{userInfoList.length}}&nbsp;部喜欢的影·音·书</div>
                <div class="main-box">
                  <scroll-view scroll-x  class="scroll-view "  style="width: 100%">  
                    <home-book  v-for="item in userMusics" :title="item.name" :link="item.cover" type="musics" :key="item" @jumpLink="jumpHomeBook"></home-book> 
                    <home-book width="112rpx" v-for="item in userBooks" :title="item.name" :link="item.cover" type="books" :key="item" @jumpLink="jumpHomeBook "></home-book> 
                    <home-book width="112rpx"  v-for="item in userMovies" :title="item.name" :link="item.cover" type="movies" :key="item" @jumpLink="jumpHomeBook"></home-book>   
                  </scroll-view>
                </div>
                <div class="footer-btn"> 
                  <button  class="tabbar-item" style="margin-left:0" open-type="share" data-name="pageShare" >
                    <div class="footer-btn-box text-center shear">分享给好友</div>  
                  </button >
                  <!--<div class="footer-btn-box text-center report">举报该用户</div> -->
                </div>
                <div class="operation">
                  <div class="icon-box"></div>
                  <div class="icon-box btn-scale" style="padding-top:8rpx;" :class="{'btn-scale-active':btnScaleShow==2}">
                    <image class="detail-out-icon " src="/static/image/home-dislike.png" @click.stop="detailChangeSelect(2)"></image> 
                  </div>
                  <div class="super-like-icon btn-scale" :class="{'btn-scale-active':btnScaleShow==3}">
                    <image class="detail-super-like" src="/static/image/home-super-like.png" @click.stop="detailChangeSelect(3)"></image>
                  </div>
                  <div class="icon-box btn-scale" style="padding-top:8rpx;"  :class="{'btn-scale-active':btnScaleShow==1}">
                    <image class="detail-like-icon" src="/static/image/home-like.png" @click.stop="detailChangeSelect(1)"></image>
                  </div>
                  <div class="icon-box"></div>
                </div> 
              </div>   
            </div>
          </div>   
        </scroll-view>   
      </swiper-item>    
          
        <!--无用户数据-->
        <swiper-item v-if="userDataList.length==0&&!bestPageShow" class="tab-content c-movble home-page" >  
          <div v-if="userDataShow" class="user-list-null" :style="'padding-top:'+headHeight+'rpx'">
            <div class="user-header"> 
              <div class="wave text-center">
                <div class="circle"></div>
                <div class="circle"></div>
                <div class="circle"></div>  
                <image  mode="aspectFill" class="content-img" :src="userInfo.head_pic?userInfo.head_pic:'https://ximi-jy.oss-cn-hangzhou.aliyuncs.com/quyue/image/head-img-undefined.png'" ></image>  
              </div> 
            </div>
            <div class="text-hit text-center">您附近没有用户，展开发现设置， 查看更多的人</div>
            <div class="find-btn text-center" @click.stop="searchUserListShow=true">发现设置</div>
              
            <div class="search-user-list-footer" v-if="searchUserListShow">
              <div class="search-content">
                <div class="title text-center">
                  发现设置
                  <i-icon type="close" size="30" color="#d8d8d8" class="float-right close-search" @click.stop="searchUserListShow=false"/>
                </div>
                <div class="main">
                  <div class="group">
                    <div class="group-title">
                      <span style="color:#FF5470;">最大距离</span>
                      <span class="float-right scope">{{distanceNum}}公里</span>
                    </div>
                    <div class="clear-both" style="width:100%;">
                      <zy-slider  sliderType="one" :minValue="distanceNum" :maxValue="160" min="2" max="160"   selectedColor="#FF5470"   backgroundColor="#E1E6EB"  @lowValueChange="distanceChange" ></zy-slider> 
                    </div>
                  </div>

                  <div class="group">
                    <div class="group-title">
                      <span style="color:#FF5470;">年龄范围</span>
                      <span class="float-right scope">{{agelow}}-{{ageheigh}}</span>
                    </div>
                    <div >
                      <zy-slider id="zy-slider" sliderType="two"  :minValue="agelow" :maxValue="ageheigh" min="16" max="60"   selectedColor="#FF5470"   backgroundColor="#E1E6EB"  @lowValueChange="lowValueChangeAction"  @heighValueChange="heighValueChangeAction" ></zy-slider> 
                    </div>
                  </div>
                  <div class="search-btn text-center" @click.stop="updatedSetInfo">更新</div>

                </div>
              </div>
              <div class="search-modal" @click.stop="searchUserListShow=false"></div>
            </div> 
          </div> 
        </swiper-item>
        <!--每日精选-->
        <swiper-item  v-if="bestPageShow" class="tab-content" >
          <div style="width:100%;height:100%;verflow:auto;"> 
            <c-bestlist
              :bestUserList="bestDataList"
              :isLikeRight="isLikeRight"
              :bestSuperLikeNum="bestSuperLikeNum"
              @change="changeBestSelect"
              @lookDetail="lookDetail"
            ></c-bestlist>
          </div>
        </swiper-item>
        <!--消息页-->
        <swiper-item  class="tab-content">
          <div :style="'padding-top:'+msgHeadHeight+'rpx;'" class="message-page">
            <!--title-->
            <div class="message-title" :style="'top:'+headHeight+'rpx;'">
              <div class="title-items" @click.stop="changeMsgTitle(0)">
                <div class=" text-center items-border-right" :class="{'title-highlight':titleHighlight==0}">消息</div>
              </div>
              <div class="title-items" @click.stop="changeMsgTitle(1)">
                <div class=" text-center"  :class="{'title-highlight':titleHighlight==1}">动态</div>
              </div> 
            </div>
            <!--内容页-->
            <div class="msg-tab-box" > 
              <!--消息-->
              <scroll-view scroll-y class="msg-tab-content msg-tab-one msg-im" :class="{'msg-tab-index':titleHighlight==0}">
                <div class="msg-search-box">
                  <div class="search-icon text-center">
                    <img  src="/static/image/msg-search.png" alt="" class="icon">
                  </div>
                  <input type="text" class="search-input" placeholder="搜索配对" v-model="searchMsgList" @input="searchMsgInput" @click.stop="clickMsgInput">
                </div>
                <!--新的配对-->
                <div class="msg-group-title">新的配对</div> 
                <div class="new-pair">
                  <scroll-view scroll-x  class="scroll-view "  style="width: 100%">  
                    <div class="praise-total" @click="jumpLikeMe">
                      <div class="pair-box">
                        <img  src="/static/image/msg-praise.png" alt="" class="img">
                        <div class="pair-num text-center">{{new_like_num>10?'10+':new_like_num}}</div>
                      </div>
                      <div class="text text-center">喜欢我的</div>
                    </div> 
                    <div class="praise-total" v-for="(item,index) in newPairData" :key="item" @click="jumpChat(item,'likeList')">
                      <div class="pair-box user-pair">
                        <img :src="item.head_pic?item.head_pic:'https://ximi-jy.oss-cn-hangzhou.aliyuncs.com/quyue/image/head-img-undefined.png'" mode="aspectFill"  alt="" class="img"> 
                        <img src="/static/image/like-other.png" alt="" class="like-other" v-if="item.pair_type==3"> 
                        <img src="/static/image/lightning.png" alt="" class="lightning" v-if="item.pair_type==1"> 
                        <img src="/static/image/super-like-other.png" alt="" class="super-like-other" v-if="item.pair_type==2"> 
                      </div>
                      <div class="text name text-center">{{item.nick_name}}</div>
                    </div>  

                  </scroll-view>
                </div>
                <!--消息-->
                <div class="msg-group-title">消息</div> 
                <div v-if="!searchMsgList">
                  <div class="msg-list" v-for="(item,index) in msgUserDataList" :key="item">
                    <div class="message-group" @click="jumpChat(item,'imList')">
                      <div class="message-head">
                          <img :src="item.head_pic?item.head_pic:'https://ximi-jy.oss-cn-hangzhou.aliyuncs.com/quyue/image/head-img-undefined.png'" mode="aspectFill"  alt="" class="head-img">
                          <!--<span class="on-line"></span>-->
                      </div>
                      <div class="message-info-box" >
                          <div class="message-info">
                              <div class="message-info-title">
                                  <span class="name">{{item.nick_name}}</span>
                                  <img src="/static/image/like-other.png" alt="" class="like-other info-icon" v-if="item.pair_type==3">
                                  <img src="/static/image/lightning.png" alt="" class="lightning info-icon" v-if="item.pair_type==1"> 
                                  <img src="/static/image/super-like-other.png" alt="" class="super-like-other info-icon" v-if="item.pair_type==2">  
                                  <span class="total float-right text-center" v-if="item.totalNum">{{item.totalNum}}</span>
                              </div>
                              <div class="message-im-text">
                                  {{item.msgCategory==2?'[图片]':item.msgCategory==5?item.category:item.content}} 
                              </div>
                          </div>
                      </div> 
                    </div>
                    <!--{{item.nickName}}:{{item.content}}-->
                  </div>
                  <div class="msg-list-null text-center" v-if="msgUserDataList.length==0">无聊天用户</div>
                </div> 
                <div v-if="searchMsgList">
                  <div class="msg-list" v-for="(item,index) in searchMsgData" :key="item">
                    <div class="message-group" @click="jumpChat(item,'imList')" >
                      <div class="message-head">
                          <img :src="item.head_pic?item.head_pic:'https://ximi-jy.oss-cn-hangzhou.aliyuncs.com/quyue/image/head-img-undefined.png'" mode="aspectFill"  alt="" class="head-img">
                          <!--<span class="on-line"></span>-->
                      </div>
                      <div class="message-info-box" >
                          <div class="message-info">
                              <div class="message-info-title">
                                  <span class="name">{{item.nick_name}}</span>
                                  <img src="/static/image/like-other.png" alt="" class="like-other info-icon" v-if="item.pair_type==3">
                                  <img src="/static/image/lightning.png" alt="" class="lightning info-icon" v-if="item.pair_type==1"> 
                                  <img src="/static/image/super-like-other.png" alt="" class="super-like-other info-icon" v-if="item.pair_type==2">  
                                  <span class="total float-right text-center" v-if="item.totalNum">{{item.totalNum}}</span>
                              </div>
                              <div class="message-im-text">
                                  {{item.msgCategory==2?'[图片]':item.msgCategory==5?item.category:item.content}} 
                              </div>
                          </div>
                      </div> 
                    </div> 
                  </div>
                  <div class="msg-list-null text-center" v-if="searchMsgData.length==0">找不到该用户</div>
                </div> 
              </scroll-view>
              <!--推送-->
              <scroll-view  scroll-y class="msg-tab-content msg-tab-two " @scrolltolower="bindscrolltolower" :class="{'msg-tab-index':titleHighlight==1}"> 
                <div class="pair-page">
                  <div v-for="(item,index) in pairDataList"  :key="index">
                    <pair-list  
                    :groupItem="item"  
                    :meLink="userInfo.head_pic"
                    @confirm="bindconfirm"
                    @jumpDetail="jumpDetail"  
                    @jumpChatPage="pairChatPage"
                    @cancelPair="cancelPair"
                    @jumpChating="jumpChating"
                    ></pair-list> 
                  </div>  
                  <div style="font-size:26rpx;color:#999;padding:30rpx;" class="text-center " v-if="pairDataListNull">暂无数据</div>
                </div>   
                <div class="text-center" style="padding:30rpx;" v-if="pairPageIndex!=pairTotalPage">
                  <span class="refresh-loading"></span>
                  <span style="display:inline-block;line-height:50rpx;font-size:26rpx;color:#999;">加载更多</span> 
                </div>
                
              </scroll-view>
            </div>
          </div> 
        </swiper-item>
    </swiper>
    <!--配对成功-->
    <div  v-if="userDataList.length>0&&!bestPageShow" >
      <match-success
        v-if="matchSuccessModal"
        :meLink="userInfo.head_pic"
        :item="matchSuccessUserInfo"
        :aloneType="aloneType"
        @close="closeMatchSuccess"
        @postSend="postSend"
      ></match-success>
    </div>
    <!--vip-->
    <div v-if="chargeVipShow">
      <charge-vip
        :vipType="operationData.vipType"
        :shareType="operationData.shareType"
        :share="operationData.can_share" 
        :aloneType="operationData.aloneType"
        :topItem="operationData.topItem"
        :current="operationData.current"
        @close="chargeVipClose"
        @successPay="successPay"
        @topBtn="topBtn"
      ></charge-vip>
    </div> 
  </div>
</template>

<script>
import * as api from '@/utils/api' ; 
import store from './store' ; 
import QQMapWX from '@/utils/qqmap-wx-jssdk.min';
import {mapKey} from '@/utils/config.js';
import homeBook from '@/components/home-book.vue' ;  
import matchSuccess from '@/components/pop-up-box/match-success.vue' ;  
import chargeVip from '@/components/pop-up-box/charge-vip.vue' ;  
// import messageList from '@/components/message-list.vue' ;  
import pairList from '@/components/pair-list.vue' ;     
import userDetailStore from './../user-detail/store' ;  
import { fetch ,postJson,fetchNullToken} from  '@/utils/httpFly' 
import {startWebSocket} from '@/utils/imeventhandler' 
let qqmapsdk;  
const app = getApp()  
export default { 
  onLoad(){ 
    let vm = this;
    vm.currentTab=1;
    startWebSocket()  //连接聊天服务器  
    app.globalData.subscriber.on('MSG_USER_DATA_LIST', this.updateRecentChat) //最近联系的人
    
    app.globalData.subscriber.on('UPDATE_MSG_LIST', (data)=>{
      this.getMsgDataList();  //获取消息列表接口
      if(data){  
        // let dataList=[...vm.msgUserDataList]; 
        // console.log('新的消息',app.globalData.recentChatList ); 
        // if(vm.GET_MESSAGE_LIST.length>0){ 
        //   vm.GET_MESSAGE_LIST.forEach((item,index)=>{   
        //     if(app.globalData.recentChatList[item.accid]){ 
        //       if(item.inShow){  
        //         dataList.forEach((msgItem,msgIndex)=>{ 
        //           if(msgItem.accid==item.accid){
        //             dataList[msgIndex].content=app.globalData.recentChatList[item.accid].content; 
        //             dataList[msgIndex].sendTime=app.globalData.recentChatList[item.accid].sendTime;
        //             dataList[msgIndex].msgCategory= app.globalData.recentChatList[item.accid].msgCategory;
        //             dataList[msgIndex].countA= app.globalData.recentChatList[item.accid].countA;   
        //             dataList[msgIndex].countB= app.globalData.recentChatList[item.accid].countB;
        //             let countA=  app.globalData.recentChatList[item.accid].countA;  //没进入 未读数
        //             let countB=  app.globalData.recentChatList[item.accid].countB;  //进入 未读数  
        //             dataList[msgIndex].totalNum=parseInt(countA)+parseInt(countB);  
        //             // console.log('更新新的消息',dataList[msgIndex]);
        //           }
        //         }) 
        //       }else{ 
        //         item.content=app.globalData.recentChatList[item.accid].content; 
        //         item.sendTime=app.globalData.recentChatList[item.accid].sendTime;
        //         item.msgCategory= app.globalData.recentChatList[item.accid].msgCategory;
        //         item.countA= app.globalData.recentChatList[item.accid].countA;   
        //         item.countB= app.globalData.recentChatList[item.accid].countB;
        //         let countA=  app.globalData.recentChatList[item.accid].countA;  //没进入 未读数
        //         let countB=  app.globalData.recentChatList[item.accid].countB;  //进入 未读数  
        //         item.totalNum=parseInt(countA)+parseInt(countB); 
        //         item.inShow=true;
        //         dataList.push(item);
        //       } 
        //     } 
        //     // console.log(dataList);
        //   }) 
          
        //   dataList.sort((a, b) => {
        //     return parseInt(b.sendTime) - parseInt(a.sendTime)
        //   })
        // } 
      }
    })  
    console.log(wx.getStorageSync('systemInfo'));
    app.aldstat.sendEvent('事件名称'); // 事件名称规范: 不超过255个字符  
    this.getLocation();   //获取地址 
    qqmapsdk = new QQMapWX({
      key: vm.mapKey
    }); 
    if(!wx.getStorageSync('refresh_token')&&!wx.getStorageSync('h_token')){
      let url = `./../login/main`;
      wx.redirectTo({url});  
    }   
    this.statusBarHeight=wx.getStorageSync('systemInfo').statusBarHeight; 
    //消息页(推送)
    this.fetchPair(); 
    //获取用户设置信息
    this.getSetInfo();
  },
  onShow: function () {  
    let vm = this;  
    //用户设置  
    if(store.state.setForm.recommand_sex&&store.state.setForm.best_choice){ 
      console.log('00');
      let ageRange=store.state.setForm.age_range.split('-');  
      ageRange[0]!='NaN'?this.agelow=parseInt(ageRange[0]):this.agelow=16;
      ageRange[1]!='NaN'?this.ageheigh=parseInt(ageRange[1]):this.ageheigh=40; 
      this.distanceNum=store.state.setForm.max_distance;
      this.updatedSetInfo();  //保存设置
    }   
    //用户基本信息
    if(store.state.userInfo.head_pic){
      this.userInfo=store.state.userInfo;
    }else{
      this.fetchInfo();
    }
    //每日精选页
    this.getBestList();
    if(userDetailStore.state.detailRuuid){
      this.deleteBestSelect(userDetailStore.state.detailRuuid); 
    } 
    //消息排序
    this.getMsgDataList();
    this.isHintShow=app.globalData.firstTime;  //是否是第一次进  
    
  },
         
  data () {
    return {   
      //
      animationData:{},
      currentTab:1,
      mapKey:mapKey,
      statusBarHeight:'',
      headHeight:wx.getStorageSync('headHeight'),
      msgHeadHeight:wx.getStorageSync('headHeight')+116,
      headPadding:wx.getStorageSync('headPadding')-6, 
      //user-page
      userPageAutoPlay:false, //是否自动播放轮播
      userInfo:{
        address:'',
        age:'',
        head_pic:'',
        nickname:'',
        location:{lat:null,lng:null},
        phone:'',
        sex:'' 
      },
      userIndexBanner: [
        'https://ximi-jy.oss-cn-hangzhou.aliyuncs.com/quyue/image/user-index-banner01.png',
        'https://ximi-jy.oss-cn-hangzhou.aliyuncs.com/quyue/image/user-index-banner02.png',
        'https://ximi-jy.oss-cn-hangzhou.aliyuncs.com/quyue/image/user-index-banner03.png',
        'https://ximi-jy.oss-cn-hangzhou.aliyuncs.com/quyue/image/user-index-banner04.png',
        'https://ximi-jy.oss-cn-hangzhou.aliyuncs.com/quyue/image/user-index-banner05.png',
        'https://ximi-jy.oss-cn-hangzhou.aliyuncs.com/quyue/image/user-index-banner06.png',
        'https://ximi-jy.oss-cn-hangzhou.aliyuncs.com/quyue/image/user-index-banner07.png',
      ],   
      userHmowCurrent:0, 
      //home-page
        homePageSwitch:1, // 1用户列表 2详情 3无用户数据
        //user-detail
        userRuuid:'', //当前查看用户的uid
        userDetailCurrent:0, 
        userDetailOffLeft:false,
        userDetailOffRight:false,
        btnScaleShow:0,  //操作按钮动画
        isSelect:0,

        //用户列表
        userDataList:[],  
        userDataShow:true,
        clearDataList:[],
        isHintShow:true,  //操作提示
        matchSuccessModal:false, //配对成功模态框
        matchSuccessUserInfo:{},
        //vip
        chargeVipShow:false,  
        operationData:{
          vipType:0,  //通用 超级喜欢  置顶
          can_share:false,
          is_vip:false,
          current:0, 
          shareType:0, 
          aloneType:-1, //  2 超级喜欢 ,1 置顶
          topItem:{
            end_time:"",
            is_top:false,
            times:0
          },
        }, 
        //用户列表轮播
        userImgList: [],
        userInfoList:{},//姓名年龄
        userBooks:[],
        userMovies:[],
        userMusics:[],
        userTwoList:{}, 
        superlikeNum:0,  
        likeNumNull:0,  //喜欢没用完
        //发现设置
        agelow:null,
        ageheigh:null,
        distanceNum:null,
        searchUserListShow:false,
        //每日精选
        bestDataList:[],  //精选列表
        bestSuperLikeNum:0,
        isLikeRight:false, //喜欢接口是否成功
        bestPageShow:false,  //每日精选页用户列表页切换
      //message-page
        titleHighlight:0,   //0消息 1推送 
        //消息
        unreadMsgNum:0, //消息数量
        searchMsgList:'', //关键词搜索
        new_like_num:0,  //喜欢我的数量
        newPairData:[], //新的配对
        IM_DATA_LIST:[],  //im消息列表
        GET_MESSAGE_LIST:[],  //所有聊过天的人
        msgUserDataList:[],    //排序后的消息列表
        searchMsgData:[],  //搜索到的聊天用户
        //推送
        pairPageIndex:1, //当前第几页
        pairTotalPage:0, //总页数
        pairLoadingShow:false, //是否显示加载更多
        pairDataList:[],  
        pairDataListNull:false,  //列表为空

        
    }
  },  
  components:{ 
    homeBook, 
    matchSuccess,
    chargeVip,
    // messageList,
    pairList
  }, 
  methods: {    
    //点击头部tabs
    jumpTabs(val,show){ 
      if(show==1){
        this.bestPageShow=false;
      }else if(show==2){
        this.bestPageShow=true;
      } 
      if(val!=1){
        this.currentTab=val; 
        if(val==2){
          //消息列表页
          this.getMsgDataList();
        }
      }else{   
        if(this.currentTab==1){ 
        } else {
          this.currentTab=val;
        }
      } 
    },
    //切换页面
    switchTab(e){
      this.currentTab=e.mp.detail.current;
      if(this.currentTab==0){
        app.aldstat.sendEvent('个人中心');  
      }else if(this.currentTab==1){
        app.aldstat.sendEvent('匹配/精选');  
      }else if(this.currentTab==2){
        app.aldstat.sendEvent('消息');  
      }
    },
    //禁止主页左右滑动
    stopTouchMove(e){
      return false;
    },
    checkSetting(){
      let vm = this;
      wx.getSetting({
        success (res) {   
          if(res.authSetting["scope.userLocation"]){ 
            vm.getLocation();
          }else{ 
            wx.openSetting({
              success (res) { 
                if(!res.authSetting["scope.userLocation"]){ 
                  // wx.showModal({
                  //   title: '用户未授权',
                  //   content: '如需正常使用小程序，请开启地理位置授权服务',
                  //   showCancel: false,
                  //   success: function (res) {
                  //     if (res.confirm) { 
                  //       // vm.checkSetting();
                  //     }
                  //   }
                  // }) 
                }else{
                  vm.getLocation();
                } 
              } 
            }) 
          }
        }
      })
    },
    //授权地址
    getLocation(){ 
      let vm = this; 
      wx.getLocation({
        type: 'wgs84',
        success (res) {  
          store.state.location=res;
           vm.getAddress(res);
        },
        fail(res){ 
        }
      }); 
    },
    getAddress(res){
      let vm = this;  
      // 调用接口
      qqmapsdk.reverseGeocoder({
        location: {
          latitude: res.latitude,
          longitude: res.longitude
        },
        success: function (ad) {
          // console.log(ad); 
          let result=ad.result;
          let body={
            lat:result.location.lat,
            lng:result.location.lng,
            address:result.address,
            city:result.address_component.city
          }
          api.uploadLocation(body).then(res=>{
            console.log(res);
            //用户列表
            vm.getUserList();
          })
        },
        fail(res){
            // vm.form.address='四川省成都市';
            console.log('拒绝授权');
        }
      })
    },
    //user-page
    /**获取用户信息 */
    fetchInfo(){
      let vm = this;
      api.getUserDetail().then(res=>{
        if(res.data.code==300000){ 
          store.state.userInfo=res.data.data;
          vm.userInfo=res.data.data;
        }
      })
    }, 
    userSwiperChange(e){
      this.userHmowCurrent=e.mp.detail.current; 
    },
    jumpPage(url){ 
      wx.navigateTo({url}); 
    },

    //home-page
    // 获取用户列表
    getUserList(val){
      let vm = this;
      let phoneInfo=wx.getStorageSync('systemInfo');
      api.getUserPageList().then(res=>{ 
        let resArr=res.data.data; 
        if(res.data.code==300000&&resArr){  
          resArr.forEach((item,index)=>{ 
            item.isShow=true;  
          })  
          if(val=='more'){
            resArr.forEach((item,index)=>{
              index==0? item.index="one":item.index=''; 
              vm.userDataList.push(item);  
            })
          }else{
            vm.userDataList=resArr;
            vm.userInfoList=resArr[0];
            vm.userImgList=resArr[0].photo;
          } 
        }else{
          vm.userImgList=[];
          vm.userDataShow=true;
        }
      })
    },
    //详情页操作
    detailChangeSelect(val){
      let vm = this; 
      vm.btnScaleShow=val;  
      setTimeout(()=>{
        vm.isSelect=val;
        vm.homePageSwitch=1;  
      },150)
      setTimeout(()=>{
        vm.btnScaleShow=0; 
        vm.postOperation(val);
      },300)
    },
    // 点击操作
    changeSelect(e){  
      let vm = this;  
      console.log(e.mp);
      let selectIndex=e.mp.detail.index;  //1喜欢 2 跳过  3 超级喜欢 4撤回 5置顶 
      if(selectIndex==1){
        app.aldstat.sendEvent('喜欢'); 
      }else if(selectIndex==2){
        app.aldstat.sendEvent('不喜欢'); 
      }else if(selectIndex==3){
        app.aldstat.sendEvent('超级喜欢');  
      } 
      if(selectIndex==1||selectIndex==2||selectIndex==3){  
        vm.postOperation(selectIndex);
        if(selectIndex==2){ 
          vm.clearDataList.push(e.mp.detail.list); 
        }
      } else if(selectIndex==4) {
        if(vm.clearDataList.length!=0){ 
          api.userpageBack().then(res=>{ 
            app.aldstat.sendEvent('撤回');
            if(res.data.code==300000){
              if(!res.data.data.can_operation){ 
                vm.operationData.can_share=res.data.data.can_share; 
                vm.operationData.shareType=3; 
                vm.operationData.vipType=0;  //通用
                vm.operationData.current=3;
                vm.chargeVipShow=true;
              }else{
                vm.userDataList.unshift(vm.clearDataList.pop()); 
                vm.clearArrOneIndex('back');
              }
            }
          }) 
        }
      }else if(selectIndex==5) { 
        //查看置顶信息
        api.fetchTopInfo().then(res=>{ 
          app.aldstat.sendEvent('置顶');
          if(res.data.code==300000){
            vm.chargeVipShow=true;
            vm.operationData.aloneType=1;
            vm.operationData.vipType=2;  //置顶
            vm.operationData.topItem=res.data.data; 
          }
        })  
      }
      // console.log(selectIndex);
    },
    //关闭操作
    isHintFun(e){ 
      this.isHintShow=e.mp.detail; 
    },
    //操作
    postOperation(val){
      let vm = this;
      let body={
        ruuid:vm.userInfoList.ruuid,
        type:parseInt(val),
        enter_page:1,  //进入页面 1.普通 2.每日精选  
        super_like:vm.userInfoList.super_like,  //	对方是否超级喜欢我
        is_top:vm.userInfoList.is_top, //对方是否置顶
      }; 
      api.userpageOperation(body).then(res=>{
        if(res.data.code==300000){  
          vm.operationData.can_share=res.data.data.can_share;
          vm.operationData.is_vip=res.data.data.is_vip;
          if(!res.data.data.can_operation){
            vm.chargeVipShow=true;
          }
          if(val==3){ 
            if(!res.data.data.can_operation){
              vm.superlikeNum=0;
              vm.operationData.vipType=res.data.data.is_vip?1:0;
              vm.operationData.aloneType=res.data.data.is_vip?2:-1;
              vm.operationData.shareType=2; //超级喜欢
              vm.operationData.current=2; 
              return;
            }else{
              let contentJson=JSON.stringify({category:1,props:null});
              if(!(app.globalData.recentChatList[vm.userInfoList.accid])){ 
                app.globalData.recentChatList[vm.userInfoList.accid] = 
                {
                nickName:vm.userInfoList.nickname,
                avatar:vm.userInfoList.photo[0].link,
                content:contentJson,
                sendTime:(new Date()).valueOf(),
                msgCategory:5,
                countA:0,
                countB:0,
                }
              } 
              vm.superlikeNum=parseInt(res.data.data.superlike_time)-1;  
            }  
          }else if(val==1){
            if(!res.data.data.can_operation){ 
              vm.likeNumNull=0;
              vm.operationData.vipType=0;
              vm.operationData.aloneType=-1;
              vm.operationData.shareType=1;  //喜欢
              vm.operationData.current=0; 
              return;
            }else{
              vm.likeNumNull=parseInt(res.data.data.like_time)-1;  
            }  
          } 
          setTimeout(()=>{  
            vm.clearArrOneIndex();
          },500) 
          if(res.data.data.pair){
            setTimeout(()=>{
              vm.matchSuccessModal=true;
            },300) 
            vm.matchSuccessUserInfo={
              head_pic:res.data.data.head_pic,
              nick_name:res.data.data.nick_name,
              ruuid:res.data.data.ruuid,
            }
          }
          
        }
        // else if(res.data.code==300111){ 
        //   vm.superlikeNum=-1;
        //   setTimeout(()=>{
        //     wx.showModal({
        //       title: '提示',
        //       content: '超级喜欢已经用完',
        //       showCancel: false, 
        //     }) 
        //   },1000) 
        // }else if(res.data.code==300110){
        //   wx.showModal({
        //     title: '提示',
        //     content: 'like已经用完',
        //     showCancel: false, 
        //   }) 
        // }
      })
    },
    // 删除数组中的第一个用户
    clearArrOneIndex(val){
      let vm = this;    
      // console.log(vm.userDataList);
      if(vm.userDataList.length>0){   
        if(val!='back'){
          vm.userDataList.shift();
        } 
        vm.userImgList=vm.userDataList[0].photo;
        vm.userInfoList.school=vm.userDataList[0].school;
        vm.userInfoList.age=vm.userDataList[0].age;
        vm.userInfoList.industry=vm.userDataList[0].industry;
        vm.userInfoList.nickname=vm.userDataList[0].nickname;
        vm.userInfoList.distance=vm.userDataList[0].distance;//距离
        vm.userInfoList.introduce=vm.userDataList[0].introduce; //介绍
        vm.userInfoList.ruuid=vm.userDataList[0].ruuid; 
        vm.userInfoList.super_like=vm.userDataList[0].super_like; 
        vm.userInfoList.is_top=vm.userDataList[0].is_top; 
        vm.userInfoList.city=vm.userDataList[0].city;  
      } else {
        vm.clearDataList=[];
        vm.userImgList=[];
        vm.userInfoList.school='';
        vm.userInfoList.age='';
        vm.userInfoList.industry='';
        vm.userInfoList.nickname='';
        vm.userInfoList.distance='';
        vm.userInfoList.introduce='';
        vm.userInfoList.ruuid=''; 
        vm.userInfoList.super_like=''; 
        vm.userInfoList.is_top=''; 
        vm.userInfoList.city=''; 
      }
      if(vm.userDataList.length==3){
        vm.getUserList('more');  //继续获取用户列表
      } 
    }, 
      // 用户详情
    //监听轮播图
    bindchange(e){  
      this.userDetailCurrent=e.mp.detail.current; 
    },
    swiperClis(val){
      let vm = this;
      if(val=='down'){
        if(vm.userDetailCurrent==0){
          vm.userDetailCurrent=0;
          vm.userDetailOffLeft=true;
          wx.vibrateShort();
          setTimeout(()=>{
            vm.userDetailOffLeft=false;
          },200); 
        }else{
          vm.userDetailCurrent--;
        }
      }else{ 
        if(vm.userDetailCurrent==vm.userImgList.length-1){
          vm.userDetailCurrent=vm.userImgList.length-1;
          vm.userDetailOffRight=true;
          wx.vibrateShort();
          setTimeout(()=>{
            vm.userDetailOffRight=false;
          },200);
        }else{
          vm.userDetailCurrent++;
        } 
      }
    },
    //影音书
    jumpHomeBook(val){  
      let url='';
      if(val=='musics'){
         url='./../../user-info/user-books/main?tabsId=1&other_uid='+this.userInfoList.ruuid
      }else if(val=='movies'){
         url='./../../user-info/user-books/main?tabsId=2&other_uid='+this.userInfoList.ruuid
      }else if(val=='books'){
         url='./../../user-info/user-books/main?tabsId=3&other_uid='+this.userInfoList.ruuid
      }
      wx.navigateTo({url});
    },
    //打开用户详情
    openDetail(e){   
      let vm = this;
      console.log(e);
      vm.homePageSwitch=2;
      vm.isSelect=0;
      vm.userDetailCurrent=e.mp.detail.current;
      vm.userRuuid=e.mp.detail.ruuid;
      vm.userBooks=[]; 
      vm.userMovies=[]; 
      vm.userMusics=[];
      api.lookMoviemusicbook({other_uuid:e.mp.detail.ruuid}).then(res=>{ 
        if(res.data.code==300000){ 
          vm.userBooks=res.data.data.books; 
          vm.userMovies=res.data.data.movies; 
          vm.userMusics=res.data.data.musics;
          vm.userInfoList.length=res.data.data.length;
        }else{
          vm.userBooks=[];
          vm.userMovies=[];
          vm.userMusics=[]; 
        }
      })
    }, 
    //发现设置
     distanceChange(e) {  
        this.distanceNum=e.mp.detail.lowValue; 
    },
    /** * 年龄范围 */
    lowValueChangeAction (e) { 
        this.agelow=e.mp.detail.lowValue; 
    },

    heighValueChangeAction (e) { 
      this.ageheigh=e.mp.detail.heighValue;  
    }, 
    //获取用户设置信息
    getSetInfo(){
      let vm = this;
      api.getUserSetting().then(res=>{
        if(res.data.code==300000){ 
          let ageRange=res.data.data.age_range.split('-');  
          ageRange[0]!='NaN'?vm.agelow=parseInt(ageRange[0]):vm.agelow=16;
          ageRange[1]!='NaN'?vm.ageheigh=parseInt(ageRange[1]):vm.ageheigh=40;  
          vm.distanceNum=res.data.data.max_distance; 
          store.state.setForm.age_range=vm.agelow+'-'+vm.ageheigh;
          store.state.setForm.max_distance=vm.distanceNum;
        }
      })
    },
    //配对成功
    closeMatchSuccess(){
      this.matchSuccessModal=false;
    },
    //配对成功发送消息
    postSend(val,item){
      let vm = this;
      if(val==''){
        wx.showModal({
          title: '提示',
          content: '发送内容不能为空',
          showCancel: false, 
        }) 
        return;
      }
      let body={
        ruuid:item.ruuid,
        content:val,
      };
      api.postMsgSend(body).then(res=>{
        if(res.data.code==300000){
          vm.matchSuccessModal=false;
        }
      })
    },
    //保存设置 (设置年龄，距离)
    updatedSetInfo() {
      let vm = this;
      let body={
        age_range:this.agelow+'-'+this.ageheigh,
        max_distance:this.distanceNum,
      };
      if(store.state.setForm.recommand_sex){
        body.recommand_sex=store.state.setForm.recommand_sex;
      } 
      if(store.state.setForm.best_choice){
        body.best_choice=store.state.setForm.best_choice;
      } 
      vm.searchUserListShow=false;
      api.updateUserSetting(body).then(res=>{
        app.aldstat.sendEvent('发现设置');
        if(res.data.code==300000){ 
          vm.getUserList();
        }
      })
    },
    //每日精选页
    getBestList(){
      let vm = this;
      api.getDailyselection().then(res=>{
        if(res.data.data){
          vm.bestDataList=res.data.data;
        }else{
          vm.bestDataList=[];
        }
      })
    },
    //每日精选操作
    changeBestSelect(val){
      let vm = this;
      console.log(val);
      let detailVal=val.mp.detail;
      let body={
        ruuid:detailVal.ruuid,
        type:parseInt(detailVal.index),
        enter_page:2,  //进入页面 1.普通 2.每日精选  
        super_like:detailVal.super_like,  //	对方是否超级喜欢我
        is_top:detailVal.is_top, //对方是否置顶
      };  
      api.userpageOperation(body).then(res=>{
        if(res.data.code==300000){
          vm.operationData.can_share=res.data.data.can_share;
          vm.operationData.is_vip=res.data.data.is_vip;
          if(!res.data.data.can_operation){
            vm.chargeVipShow=true;
          }
          //超级喜欢成功
          if(detailVal.index==3){   
            if(!res.data.data.can_operation){
              vm.bestSuperLikeNum=0;
              vm.operationData.vipType=res.data.data.is_vip?1:0;
              vm.operationData.aloneType=res.data.data.is_vip?2:-1;
              vm.operationData.shareType=3; //超级喜欢 
            } else { 
              let superContentJson=JSON.stringify({category:1,props:null});
              if(!(app.globalData.recentChatList[(detailVal.accid)])){ 
                app.globalData.recentChatList[(detailVal.accid)] = 
                {
                nickName:detailVal.nickname,
                avatar:detailVal.photo[0].link,
                content:superContentJson,
                sendTime:(new Date()).valueOf(),
                msgCategory:5,
                countA:0,
                countB:0,
                }
              }
              wx.vibrateShort();
              vm.bestSuperLikeNum=parseInt(res.data.data.superlike_time)-1; 
              setTimeout(()=>{
                vm.deleteBestSelect(detailVal.ruuid); 
              },800)  
            }  
          }else if(detailVal.index==1){ 
            if(!res.data.data.can_operation){
              vm.operationData.vipType=0;
              vm.operationData.aloneType=-1;
              vm.operationData.shareType=1; //喜欢
              vm.likeNumNull=false;//喜欢次数用完 
            } else {
              vm.isLikeRight=true; 
              setTimeout(()=>{
                vm.deleteBestSelect(detailVal.ruuid); 
                vm.isLikeRight=false;
              },500)
            }   
          } 
        } 
      }) 
    },
    //删除每日精选列表
    deleteBestSelect(uid){
      let vm = this;
      vm.bestDataList.forEach((item,index)=>{
        if(item.ruuid==uid){
          vm.bestDataList.splice(index,1)  //删除选中的元素
          userDetailStore.state.detailRuuid='';
        }
      })
    },
    //每日精选详情
    lookDetail(e){
      let item=e.mp.detail;
      console.log(item);
      if(item.is_show){
        userDetailStore.state.userDetail=item;
        wx.navigateTo({url:'./../user-detail/main'});
      }else{
        this.chargeVipShow=true;
        this.operationData.vipType=0; 
      } 
    },
  //message-page
    //tab切换
    changeMsgTitle(val){
      this.titleHighlight=val;
      if(val==0){
        this.getMsgDataList();
      }
      if(val==1){ 
        this.fetchPair();
      } 
    },
    clickMsgInput(){
      app.aldstat.sendEvent('搜索配对'); 
    },
    //搜索聊天用户
    searchMsgInput(e){ 
      let self = this;  
      if(self.msgUserDataList.length>0){
        let searchArr=[];
        self.msgUserDataList.forEach((item,index)=>{
          if(item.nick_name.search(self.searchMsgList) != -1){ 
            searchArr.push(item)
          }
        })
        self.searchMsgData=searchArr; 
      }else{
        self.searchMsgData=[];
      }
    },
    //新配对/消息列表接口
    getMsgDataList(){
      let vm = this
      api.getMsglPairList().then(res=>{ 
        if(res.data.code===300000){ 
          vm.new_like_num=res.data.data.new_like_num;
          if(res.data.data.pair_list){
            vm.newPairData=res.data.data.pair_list;
          }else{
            vm.newPairData=[];
          } 
          if(res.data.data.message_list){
            vm.GET_MESSAGE_LIST=res.data.data.message_list;
          }else{
            vm.GET_MESSAGE_LIST=[];
          }
          vm.sortChatList();  //消息排序
        }
      })
    },

    jumpLikeMe(){ 
      let vm = this; 
      api.getLikeMeList({  page:1, size:2 }).then(res=>{ 
        app.aldstat.sendEvent('喜欢我的');  
        if(res.data.code==300000){
          if(!res.data.data.can_operation){
            vm.chargeVipShow=true;
            vm.operationData.can_share=res.data.data.can_share; 
            vm.operationData.shareType=4;  
            vm.operationData.current=6;  
          }else{ 
            wx.navigateTo({url:'./../like-me-list/main'});
          }
        }
      }) 
    },

    //消息列表联系人
    updateRecentChat(res){
        // console.log('消息列表联系人',res);
        this.IM_DATA_LIST=res;
        this.getMsgDataList();  //获取消息列表接口
    },
    //排序
    sortChatList() { 
      let self= this;
      if (self.GET_MESSAGE_LIST.length != 0) {
        let chatList = []; 
        self.unreadMsgNum=0;
          self.GET_MESSAGE_LIST.forEach((list,listIndex)=>{
            if(listIndex==0){
              console.log('聊天数据',app.globalData.recentChatList); 
            } 
            if(app.globalData.recentChatList[list.accid]){  
              list.nickName=app.globalData.recentChatList[list.accid].nickName;
              list.msgCategory=app.globalData.recentChatList[list.accid].msgCategory; 
              if(list.msgCategory==5){ 
                let contentType=''; 
                if(typeof(app.globalData.recentChatList[list.accid].content) == 'string') {  
                  contentType=JSON.parse(app.globalData.recentChatList[list.accid].content).category
                }else{ 
                  contentType=app.globalData.recentChatList[list.accid].content.category;
                }
                contentType==1?list.category='[打招呼]':list.category='[评论]';
              }else{ 
                list.content=app.globalData.recentChatList[list.accid].content;
              }
              list.sendTime=app.globalData.recentChatList[list.accid].sendTime; 
              list.countA=app.globalData.recentChatList[list.accid].countA;
              list.countB=app.globalData.recentChatList[list.accid].countB; 
              list.totalNum=list.countA+list.countB; 
              self.unreadMsgNum=self.unreadMsgNum+list.totalNum;
              list.inShow=true;
              chatList.push(list) 
            } 
          })
          console.log('排序chatList',chatList); 
          // console.log('app.globalData.recentChatList',app.globalData.recentChatList); 
          chatList.sort((a, b) => {
            return parseInt(b.sendTime) - parseInt(a.sendTime)
          })  
          self.msgUserDataList=chatList; 
          self.$forceUpdate();
      }else{
        self.msgUserDataList=[];
      } 
    },
    jumpChat(item,type){ 
      item.totalNum=0; 
      let body={
        accid:item.accid,
        head_pic:item.head_pic,
        nick_name:item.nick_name,
        ruuid:item.ruuid,
        
        pair_type:item.pair_type,
        pair_time:item.pair_time || 0,
      }
      if(type=='imList'){ 
        body.countA=item.countA?item.countA:0;
        body.countB=item.countB?item.countB:0;
        app.globalData.recentChatList[item.accid].countA=0;
        app.globalData.recentChatList[item.accid].countB=0;
      } else {
        body.countA=-1;
        body.countB=-1;
      }
      // console.log('jumpChat',body);
      wx.navigateTo({url:`./../../chat-page/chat-p2p-page/main?item=${JSON.stringify(body)}`});
    },
    //滚动到底部
    bindscrolltolower(){ 
      console.log(this.pairPageIndex,this.pairTotalPage);
      if(this.pairLoadingShow&&this.pairPageIndex<this.pairTotalPage){
        console.log('滚动到底部');
        this.pairPageIndex++;
        this.fetchPair('more');
      }
    },
    //获取配对列表
    fetchPair(val=''){
      let vm = this;
      let body={
        page:vm.pairPageIndex,
        size:15,
      }; 
      vm.pairLoadingShow=false;
      api.getPairlist(body).then(res=>{
        if(res.data.code===300000){ 
          vm.pairLoadingShow=true;
          vm.pairTotalPage=res.data.data.info.total_page; 
          vm.pairPageIndex=res.data.data.info.page_num; 
          if(res.data.data.data){ 
            if(val=='more'){
              res.data.data.data.forEach((item,index)=>{
                item.update_time_text=vm.getDateDiff(item.update_time);
                item.comment_time=vm.getDateDiff(item.comment_time);
                vm.pairDataList.push(item)
              })
            }else{
              let arrData=[];
              res.data.data.data.forEach((item,index)=>{
                item.update_time_text=vm.getDateDiff(item.update_time);
                item.comment_time=vm.getDateDiff(item.comment_time);
                arrData.push(item)
              })
              vm.pairDataList=arrData;
            }
          } else{
            vm.pairDataListNull=true;
          }
        }
      })
    },
    //跳转详情
    jumpDetail(item){ 
      userDetailStore.state.userDetail=item;
      wx.navigateTo({url:'./../user-detail/main?type=pair'});
    },  
    //评论
    bindconfirm(item){ 
      console.log(item);
      let contentJson=JSON.stringify({category:2,props:{link:item.photo[0].link,msg:item.inputValue}});
      if(!(app.globalData.recentChatList[(item.accid)])){
        app.globalData.recentChatList[(item.accid)] = 
          {
          nickName:item.nickname,
          avatar:item.head_pic,
          content:contentJson,
          sendTime:(new Date()).valueOf(),
          msgCategory: 5,
          countA:0,
          countB:0,
          }
      } else {
        app.globalData.recentChatList[(item.accid)].content =contentJson;
        app.globalData.recentChatList[(item.accid)].msgCategory=5;
        app.globalData.recentChatList[(item.accid)].sendTime = (new Date()).valueOf();
        app.globalData.recentChatList[(item.accid)].countB++;
      }
    },
    //动态跳转聊天
    pairChatPage(item){
      let vm = this;
      let selfUid = JSON.parse(wx.getStorageSync('account'));   
      let data = {
        message_id:0,
        sender:item.accid,
        receiver:selfUid.accid,
        chat_category:3,
        page:1,
        size:10,
      }  
      api.getMsgsHistory(data).then(res=>{
        if(res.data.code==10000&&(res.data.data.data&&res.data.data.data!=[])){
          let body={
            accid:item.accid,
            head_pic:item.head_pic,
            nick_name:item.nickname,
            ruuid:item.ruuid, 
            pair_type:item.pair_type,
            pair_time:0,
          } 
          body.countA=app.globalData.recentChatList[item.accid].countA?app.globalData.recentChatList[item.accid].countA:0;
          body.countB=app.globalData.recentChatList[item.accid].countB?app.globalData.recentChatList[item.accid].countB:0;
          app.globalData.recentChatList[item.accid].countA=0;
          app.globalData.recentChatList[item.accid].countB=0; 
          wx.navigateTo({url:`./../../chat-page/chat-p2p-page/main?item=${JSON.stringify(body)}`});
        }else{ 
          let itemData=item;
          itemData.nick_name=item.nickname;
          vm.jumpChating(itemData); 
        }
      })
    },
    //取消配对
    cancelPair(val){
      let vm = this;
      api.postCancelPair({ruuid:val.ruuid}).then(res=>{
        if(res.data.code==300000){
          let itemArr=[];
          vm.pairDataList.forEach((item,index)=>{
            if(item.ruuid!=val.ruuid){
              itemArr.push(item);
            }
          })
          setTimeout(()=>{
            vm.pairDataList=itemArr;
          },100) 
        }
      })
    },
    //跳转聊天
    jumpChating(item){  
      let body={
        accid:item.accid,
        head_pic:item.head_pic,
        nick_name:item.nick_name || item.nickname,
        ruuid:item.ruuid, 
        pair_type:item.pair_type,
        pair_time:0,
      } 
      body.countA=0;
      body.countB=0; 
      console.log('jumpChat',body);
      wx.navigateTo({url:`./../../chat-page/chat-p2p-page/main?item=${JSON.stringify(body)}`});
    },
    //关闭充值
    chargeVipClose(){
      this.chargeVipShow=false;
    },
    //支付成功
    successPay(){
      this.chargeVipShow=false;
      this.superlikeNum=0;
    },
    topBtn(){
      let vm = this
      api.postSetTop().then(res=>{
        if(res.data.code==300000){
          if(res.data.data){
            vm.operationData.topItem=res.data.data;
            setTimeout(()=>{
              vm.chargeVipShow=false;
            },300)
          } 
        }
      })
    },
  },
  onShareAppMessage: function(res) { 
    let selfUid = JSON.parse(wx.getStorageSync('account'));  
    let path;
    let age= this.userInfoList.age!=''?`${this.userInfoList.age}岁`:'';
    let city=  this.userInfoList.city!=''?`家住${this.userInfoList.city}。`:'。';
    let introduce=  this.userInfoList.introduce!=''?`${this.userInfoList.introduce}。`:'';
    let title = `${this.userInfoList.nickname},${age}${city}来看看你们合不合得来！`;  
    let imgLink = this.userImgList[0].link; 
    if (res.from === 'button') { 
      if(this.chargeVipShow){
        title = '';
        imgLink ='';
        path = `pages/common/login/main?selfUid=${selfUid.uuid}`;
      }else{ 
        path = `pages/common/login/main?selfUid=${selfUid.uuid}&userRuuid=${this.userRuuid}`;
      } 
    }else{ 
      if(this.homePageSwitch==2) { 
        path = `pages/common/login/main?selfUid=${selfUid.uuid}&userRuuid=${this.userRuuid}`;
      } else {
        title = '';
        imgLink ='';
        path = `pages/common/login/main?selfUid=${selfUid.uuid}`;
      }
    }  
    return this.onShareAppMessage(title,path,imgLink);
  }
}
</script>
<style>
  page{
    width:100%;
    height:100%;
    overflow:hidden; 
  }
</style>
<style lang="scss" scoped> 
.swiper-change{
  width:100%;
  position:relative;
  height:988rpx;
  .block-left,.block-right{
    position:absolute;
    top:0;
    width:50%;
    height:100%;
    background:transparent;
    transform: translate3d(0, 0, 0);
    transition:all .2s;
  }
  .block-left{ 
    left:0; 
  } 
  .block-right{ 
    right:0; 
  }
}
.page-basics-content{
  position:relative;
  .page-back{
    width:128rpx;
    height:128rpx;
    position:absolute;
    top:-62rpx;
    right:42rpx;
    z-index:10;
    .img{
      height:100%;
      width:100%;
    }
  }
}
</style>
